package org.addressBook.servlet;

import com.google.gson.JsonObject;
import org.addressBook.bean.PageInfo;
import org.addressBook.bean.TableData;
import org.addressBook.bean.TbUser;
import org.addressBook.service.TbUserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

public class ManageServlet extends HttpServlet {
    TbUserService us = new TbUserService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userName = (String) request.getSession().getAttribute("name");
        PrintWriter out = response.getWriter();
        JsonObject json = null;

        /**
         * 当客户端调用此接口时，先进行数据查找，由于是自己查找数据表，所以需要查找数据表里面的全部的值
         * 把获得的记录转换为json类型，在查询的时候已经实现
         */
        try {
            json = us.jsonService(userName); //
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        out.print(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
}
